<!DOCTYPE HTML>
<title>SVGTransform interface</title>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script>
test(function() {
  // This test checks the SVGTransform API.

  var svgElement = document.createElementNS("http://www.w3.org/2000/svg", "svg");
  var transform = svgElement.createSVGTransform();

  // Check initial transform values.
  assert_equals(transform.type, SVGTransform.SVG_TRANSFORM_MATRIX);
  assert_equals(transform.angle, 0);
  assert_equals(transform.matrix.a, 1);
  assert_equals(transform.matrix.b, 0);
  assert_equals(transform.matrix.c, 0);
  assert_equals(transform.matrix.d, 1);
  assert_equals(transform.matrix.e, 0);
  assert_equals(transform.matrix.f, 0);

  // Change to skewX transformation.
  transform.setSkewX(45);
  assert_equals(transform.type, SVGTransform.SVG_TRANSFORM_SKEWX);
  assert_equals(transform.angle, 45);
  assert_equals(transform.matrix.a, 1);
  assert_equals(transform.matrix.b, 0);
  assert_equals(transform.matrix.c.toFixed(1), "1.0");
  assert_equals(transform.matrix.d, 1);
  assert_equals(transform.matrix.e, 0);
  assert_equals(transform.matrix.f, 0);

  // Changing matrix.e to 100, should reset transformation type to MATRIX, and angle should be 0.
  transform.matrix.e = 100;
  assert_equals(transform.matrix.e, 100);
  assert_equals(transform.type, SVGTransform.SVG_TRANSFORM_MATRIX);
  assert_equals(transform.angle, 0);
  assert_equals(transform.matrix.a, 1);
  assert_equals(transform.matrix.b, 0);
  assert_equals(transform.matrix.c.toFixed(1), "1.0");
  assert_equals(transform.matrix.d, 1);
  assert_equals(transform.matrix.e, 100);
  assert_equals(transform.matrix.f, 0);

  // Now revert to initial matrix.
  transform.matrix.c = 0;
  transform.matrix.e = 0;
  assert_equals(transform.matrix.c, 0);
  assert_equals(transform.matrix.e, 0);
  assert_equals(transform.type, SVGTransform.SVG_TRANSFORM_MATRIX);
  assert_equals(transform.angle, 0);
  assert_equals(transform.matrix.a, 1);
  assert_equals(transform.matrix.b, 0);
  assert_equals(transform.matrix.c, 0);
  assert_equals(transform.matrix.d, 1);
  assert_equals(transform.matrix.e, 0);
  assert_equals(transform.matrix.f, 0);

  // Check passing invalid arguments to 'setMatrix'.
  assert_throws_js(TypeError, function() { transform.setMatrix(); });
  assert_throws_js(TypeError, function() { transform.setMatrix(transform); });
  assert_throws_js(TypeError, function() { transform.setMatrix(svgElement); });
  assert_throws_js(TypeError, function() { transform.setMatrix('aString'); });
  assert_throws_js(TypeError, function() { transform.setMatrix(1); });
  assert_throws_js(TypeError, function() { transform.setMatrix(false); });

  // Check passing invalid arguments to 'setTranslate'.
  assert_throws_js(TypeError, function() { transform.setTranslate(); });
  assert_throws_js(TypeError, function() { transform.setTranslate(transform); });
  assert_throws_js(TypeError, function() { transform.setTranslate(svgElement); });
  assert_throws_js(TypeError, function() { transform.setTranslate('aString'); });
  assert_throws_js(TypeError, function() { transform.setTranslate(1, transform); });
  assert_throws_js(TypeError, function() { transform.setTranslate(1, svgElement); });
  assert_throws_js(TypeError, function() { transform.setTranslate(1, 'aString'); });
  assert_throws_js(TypeError, function() { transform.setTranslate(transform, 1); });
  assert_throws_js(TypeError, function() { transform.setTranslate(svgElement, 1); });
  assert_throws_js(TypeError, function() { transform.setTranslate('aString', 1); });
  assert_throws_js(TypeError, function() { transform.setTranslate(transform, transform); });
  assert_throws_js(TypeError, function() { transform.setTranslate(svgElement, svgElement); });
  assert_throws_js(TypeError, function() { transform.setTranslate('aString', 'aString'); });
  assert_throws_js(TypeError, function() { transform.setTranslate(NaN, 1); });
  assert_throws_js(TypeError, function() { transform.setTranslate(Infinity, 1); });
  assert_throws_js(TypeError, function() { transform.setTranslate(1, NaN); });
  assert_throws_js(TypeError, function() { transform.setTranslate(1, Infinity); });

  // Check passing invalid arguments to 'setScale'.
  assert_throws_js(TypeError, function() { transform.setScale(); });
  assert_throws_js(TypeError, function() { transform.setScale(transform); });
  assert_throws_js(TypeError, function() { transform.setScale(svgElement); });
  assert_throws_js(TypeError, function() { transform.setScale('aString'); });
  assert_throws_js(TypeError, function() { transform.setScale(1, transform); });
  assert_throws_js(TypeError, function() { transform.setScale(1, svgElement); });
  assert_throws_js(TypeError, function() { transform.setScale(1, 'aString'); });
  assert_throws_js(TypeError, function() { transform.setScale(transform, 1); });
  assert_throws_js(TypeError, function() { transform.setScale(svgElement, 1); });
  assert_throws_js(TypeError, function() { transform.setScale('aString', 1); });
  assert_throws_js(TypeError, function() { transform.setScale(transform, transform); });
  assert_throws_js(TypeError, function() { transform.setScale(svgElement, svgElement); });
  assert_throws_js(TypeError, function() { transform.setScale('aString', 'aString'); });
  assert_throws_js(TypeError, function() { transform.setScale(NaN, 1); });
  assert_throws_js(TypeError, function() { transform.setScale(Infinity, 1); });
  assert_throws_js(TypeError, function() { transform.setScale(1, NaN); });
  assert_throws_js(TypeError, function() { transform.setScale(1, Infinity); });

  // Check passing invalid arguments to 'setRotate'.
  assert_throws_js(TypeError, function() { transform.setRotate(); });
  assert_throws_js(TypeError, function() { transform.setRotate(transform); });
  assert_throws_js(TypeError, function() { transform.setRotate(svgElement); });
  assert_throws_js(TypeError, function() { transform.setRotate('aString'); });
  assert_throws_js(TypeError, function() { transform.setRotate(1, transform); });
  assert_throws_js(TypeError, function() { transform.setRotate(1, svgElement); });
  assert_throws_js(TypeError, function() { transform.setRotate(1, 'aString'); });
  assert_throws_js(TypeError, function() { transform.setRotate(1, 1, transform); });
  assert_throws_js(TypeError, function() { transform.setRotate(1, 1, svgElement); });
  assert_throws_js(TypeError, function() { transform.setRotate(1, 1, 'aString'); });
  assert_throws_js(TypeError, function() { transform.setRotate(NaN, 1, 1); });
  assert_throws_js(TypeError, function() { transform.setRotate(Infinity, 1, 1); });
  assert_throws_js(TypeError, function() { transform.setRotate(1, NaN, 1); });
  assert_throws_js(TypeError, function() { transform.setRotate(1, Infinity, 1); });
  assert_throws_js(TypeError, function() { transform.setRotate(1, 1, NaN); });
  assert_throws_js(TypeError, function() { transform.setRotate(1, 1, Infinity); });

  // Check passing invalid arguments to 'setSkewX'.
  assert_throws_js(TypeError, function() { transform.setSkewX(); });
  assert_throws_js(TypeError, function() { transform.setSkewX(transform); });
  assert_throws_js(TypeError, function() { transform.setSkewX(svgElement); });
  assert_throws_js(TypeError, function() { transform.setSkewX('aString'); });
  assert_throws_js(TypeError, function() { transform.setSkewX(NaN); });
  assert_throws_js(TypeError, function() { transform.setSkewX(Infinity); });

  // Check passing invalid arguments to 'setSkewY'.
  assert_throws_js(TypeError, function() { transform.setSkewY(); });
  assert_throws_js(TypeError, function() { transform.setSkewY(transform); });
  assert_throws_js(TypeError, function() { transform.setSkewY(svgElement); });
  assert_throws_js(TypeError, function() { transform.setSkewY('aString'); });
  assert_throws_js(TypeError, function() { transform.setSkewY(NaN); });
  assert_throws_js(TypeError, function() { transform.setSkewY(Infinity); });
});
</script>